package com.services.facade;

import com.services.domain.Departments;

import java.util.Hashtable;

import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EnterpriseSessionFacadeClient {
    public static void main(String [] args) {
        try {
            final Context context = getInitialContext();
            EnterpriseSessionFacade enterpriseSessionFacade = (EnterpriseSessionFacade)context.lookup("ejb/EnterpriseSessionFacade#com.services.facade.EnterpriseSessionFacade");
            
            long deptId = 10;
            List<Departments> depts  = enterpriseSessionFacade.findAllDepartments();
            System.out.println("***********Depatments List" + depts.size());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private static Context getInitialContext() throws NamingException {
        Hashtable env = new Hashtable();
        // WebLogic Server 10.x connection details
        env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
        env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
        return new InitialContext( env );
    }
}
